package com.zlt.appparking;

import org.apache.ibatis.io.Resources;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.InvalidConfigurationException;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import java.util.ArrayList;

/**
 * Hello world!
 *
 */
public class App {
    public static void main( String[] args ) {
        Reader resourceAsReader = null;
        try {
            resourceAsReader = Resources.getResourceAsReader("generatorConfig.xml");
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            ArrayList<String> warnings = new ArrayList<>();
            //创建配置对象
            Configuration configuration = new ConfigurationParser(warnings).parseConfiguration(resourceAsReader);
            //创建生成器对象
            MyBatisGenerator myBatisGenerator = new MyBatisGenerator(configuration, new DefaultShellCallback(false), warnings);
            //执行生成
            myBatisGenerator.generate(null);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (XMLParserException e) {
            e.printStackTrace();
        } catch (InvalidConfigurationException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
